package MarrySum5;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class MarryCountBean  implements Writable {
    private float fmarry;//初婚
    private float remarry;//再婚

    public MarryCountBean(){
    }

    public MarryCountBean(float fmarry,float remarry){
        this.fmarry = fmarry;
        this.remarry = remarry;
    }

    public void set(float fmarry,float remarry){
        this.fmarry = fmarry;
        this.remarry = remarry;
    }

    public float getFmarry(){
        return fmarry;
    }
    public void setFmarry(float fmarry){
        this.fmarry = fmarry;
    }

    public float getRemarry(){
        return remarry;
    }

    public void setRemarry(float remarry){
        this.remarry = remarry;
    }

    @Override
    public String toString() {
        return " " +
                "初婚数=" + fmarry +
                ",再婚数=" + remarry;

    }

    /**
     * 序列化方法，可以控制把哪写字段序列化出去
     */
    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeFloat(fmarry);
        dataOutput.writeFloat(remarry);
    }

    /**
     *  反序列化方法
     *  todo 注意反序列化的顺序和序列化顺序一致
     */
    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.fmarry = dataInput.readFloat();
        this.remarry = dataInput.readFloat();
    }
}
